
#include "testApp.h"



void testApp::setup(){

    // Shapes
    //
    
    sxRectangleShape* myRect = new sxRectangleShape(50, 20);
    myRect->setPosition(100, 630, 0);
    myRect->setPivot(25,10,0);
    myRect->addRotationZ(45);
    myRect->setColor(1.0, 0.19, 0.14, 1.0);
    scene->addChild(myRect);

    sxEllipseShape* myElli = new sxEllipseShape(50, 50);
    myElli->setPosition(200, 630, 0);
    myElli->setResolution(60);
    //myElli->setPivot(150,25,0);
    //myElli->addRotationZ(45);
    myElli->setColor(1.0, 0.19, 0.14, 1.0);
    scene->addChild(myElli);

    sxMonsterShape* myMonster = new sxMonsterShape();
    myMonster->setPosition(500, 580, 0);
    myMonster->setScale(0.5);
    myMonster->setColor(1.0, 0.19, 0.14, 1.0);
    scene->addChild(myMonster);

    
    // Images
    //
    
    imagepng = new sxImageShape();
    imagepng->loadImage("image.png");
    imagepng->setPivot(0.5*imagepng->getWidth(), 0.0f, 0.0f);    
    imagepng->setPosition(200,400,0);
    imagepng->setScale(0.5);
    scene->addChild(imagepng);    

    imagejpg = new sxImageShape();
    imagejpg->loadImage("image.jpg");
    imagejpg->setPivot(0.5*imagejpg->getWidth(), 0.0f, 0.0f);
    imagejpg->setPosition(420,400,0);
    imagejpg->setScale(0.3);
    scene->addChild(imagejpg);

    imagebmp = new sxImageShape();
    imagebmp->loadImage("image.bmp");
    imagebmp->setPivot(0.5*imagebmp->getWidth(), 0.0f, 0.0f);        
    imagebmp->setPosition(600,400,0);
    imagebmp->setScale(0.6f);
    scene->addChild(imagebmp);
    
    
    // Models
    // 
        
    spaceship = new sxModel();
    spaceship->loadModel("spaceship.osg");
    spaceship->setPosition(200,200,0);
    spaceship->setScale(5);
    scene->addChild(spaceship);

    modelobj = new sxModel();
    modelobj->loadModel("samurai.obj");
    modelobj->setPosition(300,200,0);
    modelobj->setScale(10);
    scene->addChild(modelobj);

    model3ds = new sxModel();
    model3ds->loadModel("katana.3ds");
    model3ds->setPosition(400,200,0);
    model3ds->setScale(10);
    scene->addChild(model3ds);

    modelstl = new sxModel();
    modelstl->loadModel("dome.stl");
    modelstl->setPosition(520,200,0);
    modelstl->setScale(10);
    scene->addChild(modelstl);

    sxSliderWidget* rotSlider = new sxSliderWidget();
    rotSlider->setName("Rotation");
    rotSlider->setShape(400,40);
    rotSlider->setPosition(150,80);
    rotSlider->setValueMin(-3.14);
    rotSlider->setValueMax(3.14);
    rotSlider->addEventHandler(this);
    scene->addChild(rotSlider);

}



void testApp::update(){}
void testApp::exit(){}
void testApp::resized( int w, int h ){}


void testApp::keyPress( sxKey& key ){}
void testApp::keyRelease( sxKey& key ){}


void testApp::mousePress( sxMouse& mouse ){}
void testApp::mouseRelease( sxMouse& mouse ){}
void testApp::mouseMove( sxMouse& mouse ){}
void testApp::mouseDrag( sxMouse& mouse ){}
void testApp::mouseScroll( sxMouse& mouse ){}
void testApp::mouseDoubleclick( sxMouse& mouse ){}


void testApp::touchDown( sxTouch& touch ){}
void testApp::touchUp( sxTouch& touch ){}
void testApp::touchMove( sxTouch& touch ){}


void testApp::penPressure( sxPen& pen ){}
void testApp::penOrientation( sxPen& pen ){}
void testApp::penEnter( sxPen& pen ){}
void testApp::penLeave( sxPen& pen ){}


void testApp::widgetButton( sxButtonWidget& button ) {}
void testApp::widgetSlider( sxSliderWidget& slider ) {

    // make objects respond to slider
    //
    
    imagepng->setRotation(-6*slider.getValue(), 0.0f, 1.0f, 0.0f);
    imagejpg->setRotation(6*slider.getValue(), 0.0f, 1.0f, 0.0f);
    imagebmp->setRotation(-6*slider.getValue(), 0.0f, 1.0f, 0.0f);

    spaceship->resetRotation();
    spaceship->addRotationY(slider.getValue());
    spaceship->addRotationX(0.25*slider.getValue());

    modelobj->setRotation(slider.getValue(), 0.0f, 1.0f, 0.0f);
    model3ds->setRotation(-slider.getValue(), 0.0f, 0.0f, 1.0f);
    modelstl->setRotation(-slider.getValue(), 1.0f, 0.0f, 0.0f);
}
void testApp::widgetCheckbox( sxCheckboxWidget& checkbox ) {}


